﻿package src.computation 
{
	
	/**
	* 
	* Reliability project
	* -----------------------
	* @author  Dmitrij Boycov
	* @mail    dmitry.boycov@gmail.com
	* @date    April 27, 2010
	* @version 1
	* 
	*/
	
	import fl.controls.CheckBox; 
	import flash.events.Event;
	// astra
	import com.yahoo.astra.containers.formClasses.FormItem;	
	import com.yahoo.astra.layout.LayoutContainer;
	import com.yahoo.astra.layout.modes.BoxLayout;
	import com.yahoo.astra.containers.formClasses.FormLayoutStyle;
	//src
	import src.computation.distributionLaw.NormLaw; 
	
	public class Recovery extends LayoutContainer {
		
		private var law = null;
		
		/**
		 * construct
		 */
		public function Recovery() {		
			var cb = new CheckBox();
			cb.addEventListener(Event.CHANGE, changeRecovery);
			cb.label = "";
			// form item
			var cbFormItem  = new FormItem("Учитывать востановление?", cb);
			cbFormItem.labelAlign = FormLayoutStyle.RIGHT;
			cbFormItem.labelWidth = 150;
			//panel
			var box : BoxLayout = new BoxLayout();			
			box.direction = "vertical";
			box.verticalGap = 10;		
			super(box);			
			this.autoMask = false;
			this.addChild(cbFormItem);
		}
		
		/**
		 * changeRecovery
		 * @param	event
		 */
		private function changeRecovery(event) {
			var cb:CheckBox = CheckBox(event.target);
			if (cb.selected) {
				if (this.numChildren < 2 ) {
					this.law = new NormLaw();
					this.addChildAt(this.law, 1);
				}
			}else {
				if (this.numChildren > 1 ) {
					this.removeChildAt(1);
				}
			}			
		}
		
		public function setSystemWorkTime(t) {
			if(this.law!=null){
				this.law.setTime(t);
			}
		}
		
		public function getTime() {
			if (this.law == null) {
				return -1;
			}
			return this.law.random();
		}
		
	}
	
}